ConfigurationManager.AppSettings[key] is always null

Posted by Copeleto on Stack Overflow See other posts from Stack Overflow or by Copeleto
Published on 2010-04-17T22:48:56Z Indexed on 2010/04/17 22:53 UTC
Read the original article Hit count: 338

Filed under:

Hi,

I am trying to get the value for the key "sUser" in this appSetting

http://coomeva1/AsisaWS_2008/ConsultaNuips.asmx http://coomeva1/AsisaWS_2008_Sec/ConsultaNuips.asmx http://coomeva1/AsisaWS_2008/ConsultaCedulaExtranjeria.asmx http://coomeva1/AsisaWS_2008_Sec/ConsultaCedulaExtranjeria.asmx userbancolombia 8909039388

this is the code on my class.cs

string sUsr = ConfigurationManager.AppSettings.Get["sUser"];

But always its null.

I try this code (I took it from http://msdn.microsoft.com/en-us/library/system.configuration.appsettingssection.settings.aspx):

// Get the configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

        // Get the appSettings section.
        AppSettingsSection appSettings =
            (AppSettingsSection)config.GetSection("appSettings");

        // Get the auxiliary file name.
        Console.WriteLine("Auxiliary file: {0}", config.AppSettings.File);

But it shows that the file Empty

Also I am ussing the consolo to write those properties and it works if I get the apps using

string sUsr = WIW.Business.Properties.Settings.Default.sUser;

But I am going to use that class as a reference in a website and on the web.config of the site i cant configure those

Thanks for your help

© Stack Overflow or respective owner

Related posts about c#3.0